import router from "./router";
// @ts-ignore
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import useUserStore from "./store/modules/user";

//小圆球效果无
Nprogress.configure({ showSpinner: false })


let whiteRouter = ['/home', '/', '/hospital/register', '/hospital/detail', '/hospital/register']

//前置路由
router.beforeEach((to, from, next) => {
    let userStore = useUserStore()
    let token = userStore.userInfo.token
    Nprogress.start()
    document.title = `尚医通-${to.name}`

    if (token) {
        next()
    } else {
        if (whiteRouter.includes(to.path)) {
            next()
        } else {
            userStore.visible = true
            next(`/home?redirect=${to.fullPath}`)
        }
    }
})

//后置路由
router.afterEach((to, from) => {
    Nprogress.done()
})